<?php

class Jd_hunter_total_day_model extends MY_Model {

    public function __construct()
    {
        $this->modelename='Jd_hunter_total_day_model';
        $this->tablename='hunter_total_day';
        parent::__construct();
    }


    /**
     * 检查插入或者更新数据
     */
    public function getupodate($row){
        $date=date('Y-m-d');
        $user_id=$row['user_id'];
        $money=$row['money'];
        $row['addtime']=time();
        $sql="select 1 from jd_hunter_total_day where `date`='$date' AND  user_id=$user_id ";


        if(isset($row['finishnub'])){
            $finishnub=intval($row['finishnub']);
        }else{
            $finishnub=1;
        }

        $result=$this->GetBySql($sql,0);
        if(empty($result)){
            $row['usemoney']=$money;
            unset( $row['money']);
            $row['finishnub']=$finishnub;
            $row['date']=$date;
            return  $this->add($this->tablename,$row);
        }else{
            $sql='update jd_hunter_total_day set  finishnub=finishnub+'.$finishnub.' ,usemoney=usemoney+'.$money ." where `date`='$date' AND  user_id=$user_id ";
            return $this->db->query($sql);
        }
    }


    /**
     * 更新今日打款
     * @param $row
     * @return INT
     */
    public function addsendmoney($row){
        $date=date('Y-m-d');
        $user_id=$row['user_id'];
        $money=$row['money'];
        $row['addtime']=time();
        $sql="select 1 from jd_hunter_total_day where `date`='$date' AND  user_id=$user_id ";




        $result=$this->GetBySql($sql,0);
        if(empty($result)){
            $row['sendmoney']=$money;
            $row['date']=$date;
            unset( $row['money']);
            return  $this->add($this->tablename,$row);
        }else{
            $sql='update jd_hunter_total_day set  sendmoney=sendmoney+'.$money ." where `date`='$date' AND  user_id=$user_id ";
            return $this->db->query($sql);
        }
    }










}
